package com.fpj.sat.vehicle_administrator.view.dialog;

import java.awt.Component;
import java.awt.Font;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.fpj.sat.vehicle_administrator.action.VehiculoAction;
import com.fpj.sat.vehicle_administrator.domain.RegistroVehiculo;
import com.fpj.sat.vehicle_administrator.util.JLinkButton;
import com.fpj.sat.vehicle_administrator.util.JTextFieldLimit;
import com.fpj.sat.vehicle_administrator.util.Util;
import com.fpj.sat.vehicle_administrator.view.PrincipalFrame;

public class CorreoDialog extends JDialog{
	
	private static final long serialVersionUID = 6072235967678701540L;
	private VehiculoAction vehiculoAction;
	private JLabel lblTitulo;
	private JLabel lblFrom;
	private JLabel lblTo;
	private JLabel lblSubject;
	private JLabel lblAttachment;
	private JTextField txtCorreoFrom;
	private JList<String> lstCorreosIni;
	private DefaultListModel<String> modelCorreosIni;
	private JScrollPane spCorreosIni;
	private JList<String> lstCorreosTo;
	private DefaultListModel<String> modelCorreosTo;
	private JScrollPane spCorreosTo;
	private JTextField txtCorreoTo;
	private JTextField txtSubject;
	private JTextArea txtMessage;
	private JButton btnAddTo;
	private JButton btnAddNewTo;
	private JButton btnRemoveTo;
	private JLinkButton lnkAttachment;
	private JButton btnSend;
	
	public CorreoDialog(DetalleRegistroDialog detalleRegistroDialog, PrincipalFrame principal, RegistroVehiculo registroVehiculo) {
    	super(detalleRegistroDialog);
    	this.vehiculoAction = new VehiculoAction(this, null, principal, registroVehiculo);
        inicializaDialog();
        inicializaComponentes();
        inicializaData();
    }

	private void inicializaDialog() {
		setLayout(null);
		setBounds(Util.getAnchoPantalla(getToolkit().getScreenSize(), 0.2), 0, Util.getAnchoPantalla(getToolkit().getScreenSize(), 0.5), Util.getAltoPantalla(getToolkit().getScreenSize(), 0.95));
        setTitle("Envio de Correo");
	}
    
    private void inicializaComponentes() {
		lblTitulo = new JLabel("ENVIO DE CORREO");
		lblTitulo.setFont(new Font(lblTitulo.getFont().getFontName(), Font.BOLD, 16));
		lblTitulo.setBounds(Util.getPorcentaje(getWidth(), 0.5) - 120, 40, 300, 25);
		
		lblFrom = new JLabel("DE:");
		lblFrom.setBounds(50, 100, 40, 20);
		
		lblTo = new JLabel("PARA:");
		lblTo.setBounds(50, 180, 60, 20);
		
		lblSubject = new JLabel("ASUNTO:");
		lblSubject.setBounds(50, 350, 80, 20);
		
		lblAttachment = new JLabel("ADJUNTO:");
		lblAttachment.setBounds(50, 380, 80, 20);
		
		txtCorreoFrom = new JTextField();
		txtCorreoFrom.setBounds(120, 100, 180, 30);
		txtCorreoFrom.setEditable(false);
		txtCorreoFrom.setFocusable(false);
		
		modelCorreosIni = new DefaultListModel<String>();
		lstCorreosIni = new JList<String>(modelCorreosIni);
		lstCorreosIni.setVisibleRowCount(-1);
		spCorreosIni = new JScrollPane(lstCorreosIni);
		spCorreosIni.setBounds(120, 130, 180, 172);
		
		modelCorreosTo = new DefaultListModel<String>();
		lstCorreosTo = new JList<String>(modelCorreosTo);
		lstCorreosTo.setVisibleRowCount(-1);
		spCorreosTo = new JScrollPane(lstCorreosTo);
		spCorreosTo.setBounds(400, 130, 180, 200);
		
		txtCorreoTo = new JTextField();
		txtCorreoTo.setBounds(120, 302, 180, 30);
		txtCorreoTo.setDocument(new JTextFieldLimit(80));
		
		txtSubject = new JTextField();
		txtSubject.setBounds(120, 350, Util.getPorcentaje(getWidth(), 0.735), 25);
		txtSubject.setDocument(new JTextFieldLimit(150));
		
		lnkAttachment = new JLinkButton();
		lnkAttachment.setBounds(120, 380, 180, 25);
		lnkAttachment.addActionListener(this.vehiculoAction);
		
		txtMessage = new JTextArea();
		txtMessage.setBounds(50, 410, Util.getPorcentaje(getWidth(), 0.84), Util.getPorcentaje(getHeight(), 0.25));
		
		btnAddTo = new JButton(">>");
		btnAddTo.setBounds(330, 180, 45, 25);
		btnAddTo.addActionListener(this.vehiculoAction);
		
		btnRemoveTo = new JButton("<<");
		btnRemoveTo.setBounds(330, 210, 45, 25);
		btnRemoveTo.addActionListener(this.vehiculoAction);
		
		btnAddNewTo = new JButton(">>");
		btnAddNewTo.setBounds(330, 307, 45, 25);
		btnAddNewTo.addActionListener(this.vehiculoAction);
		
		btnSend = new JButton("Enviar");
		btnSend.setBounds(280, Util.getPorcentaje(getHeight(), 0.88), 100, 25);
		btnSend.addActionListener(this.vehiculoAction);
		
		agregarComponentes(lblTitulo, lblFrom, lblTo, lblSubject, lblAttachment, txtCorreoFrom, spCorreosIni, 
				spCorreosTo, txtCorreoTo, txtSubject, lnkAttachment, txtMessage, btnAddTo, btnRemoveTo, btnAddNewTo, btnSend);
    }
    
    private void inicializaData() {
		vehiculoAction.cargarCorreosIni();
		
	}
    
    private void agregarComponentes(Component...componentes){
		for(Component component: componentes){
			add(component);
		}
		
	}

	public JTextField getTxtCorreoFrom() {
		return txtCorreoFrom;
	}

	public void setTxtCorreoFrom(JTextField txtCorreoFrom) {
		this.txtCorreoFrom = txtCorreoFrom;
	}

	public JList<String> getLstCorreosIni() {
		return lstCorreosIni;
	}

	public void setLstCorreosIni(JList<String> lstCorreosIni) {
		this.lstCorreosIni = lstCorreosIni;
	}

	public DefaultListModel<String> getModelCorreosIni() {
		return modelCorreosIni;
	}

	public void setModelCorreosIni(DefaultListModel<String> modelCorreosIni) {
		this.modelCorreosIni = modelCorreosIni;
	}

	public JList<String> getLstCorreosTo() {
		return lstCorreosTo;
	}

	public void setLstCorreosTo(JList<String> lstCorreosTo) {
		this.lstCorreosTo = lstCorreosTo;
	}

	public DefaultListModel<String> getModelCorreosTo() {
		return modelCorreosTo;
	}

	public void setModelCorreosTo(DefaultListModel<String> modelCorreosTo) {
		this.modelCorreosTo = modelCorreosTo;
	}

	public JTextField getTxtCorreoTo() {
		return txtCorreoTo;
	}

	public void setTxtCorreoTo(JTextField txtCorreoTo) {
		this.txtCorreoTo = txtCorreoTo;
	}

	public JTextField getTxtSubject() {
		return txtSubject;
	}

	public void setTxtSubject(JTextField txtSubject) {
		this.txtSubject = txtSubject;
	}

	public JTextArea getTxtMessage() {
		return txtMessage;
	}

	public void setTxtMessage(JTextArea txtMessage) {
		this.txtMessage = txtMessage;
	}

	public JButton getBtnAddTo() {
		return btnAddTo;
	}

	public void setBtnAddTo(JButton btnAddTo) {
		this.btnAddTo = btnAddTo;
	}

	public JButton getBtnAddNewTo() {
		return btnAddNewTo;
	}

	public void setBtnAddNewTo(JButton btnAddNewTo) {
		this.btnAddNewTo = btnAddNewTo;
	}

	public JButton getBtnRemoveTo() {
		return btnRemoveTo;
	}

	public void setBtnRemoveTo(JButton btnRemoveTo) {
		this.btnRemoveTo = btnRemoveTo;
	}

	public JLinkButton getLnkAttachment() {
		return lnkAttachment;
	}

	public void setLnkAttachment(JLinkButton lnkAttachment) {
		this.lnkAttachment = lnkAttachment;
	}

	public JButton getBtnSend() {
		return btnSend;
	}

	public void setBtnSend(JButton btnSend) {
		this.btnSend = btnSend;
	}
}
